package co.yixiang.security.test;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import java.util.Observable;
import java.util.Observer;

@RequiredArgsConstructor
public class ObservableReader implements Observer {

    @NonNull
    private String name;

    private String article;


    private void updateArticle(Observable o){
        ObervaleProvider provider = (ObervaleProvider)o;
        this.article = provider.getArticle();
        System.out.printf("我是读者：%s，文章已更新为：%s \n", this.name, this.article);
    }

    /**
     * This method is called whenever the observed object is changed. An
     * application calls an <tt>Observable</tt> object's
     * <code>notifyObservers</code> method to have all the object's
     * observers notified of the change.
     *
     * @param o   the observable object.
     * @param arg an argument passed to the <code>notifyObservers</code>
     */
    @Override
    public void update(Observable o, Object arg) {
//        System.out.println("arg"+ arg.toString());
        updateArticle(o);
    }
}
